var app = getApp()
Page({
  data: {
    author: 'Lotus'
  },
  formSubmit: function (e) {

    var that = this;
    //var keyword = e.detail.value;  
    //console.log('form发生了submit事件，携带数据为：',e.detail.value);
    const params = e.detail.value
    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList[0]
      //console.log("param:" + error.param+"msg:" + error.msg)
      wx.showToast({
        title: error.msg,
        icon: 'error',
        duration: 2000
      })
      return false
    }

    var service = 'App.feedback';
    var content = e.detail.value.content;
    var weiXie = e.detail.value.weiXie;
    var email = e.detail.value.email;
/* 
    console.log("openId:" + app.globalData.openId)
    console.log("content:" + content)
    console.log("weiXie:" + weiXie)
    console.log("email:" + email)
*/
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, content: content, weiXie: weiXie, email: email },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        //console.log("success:" + res.data.data)
        wx.switchTab({
          url: 'index'
        })
      },
      fail: function (res) {
        console.log("fail:" + res)
      },
    })

  },
  formReset: function () {
    //console.log('form发生了reset事件')
  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode=options.fromInviteCode;
    }
    app.appstart();

    that.WxValidate = app.WxValidate({
      content: {
        required: true,
        minlength: 1,
      }
    }, {
        content: {
          required: '请输入内容',
        }
      })
  }
})